
/*
    file:       main.h

    purpose:    definitions and macros for main.c

    revisions
    000     RLL     2011-02-11  created file
    001     RLL     2011-02-25  renamed to main.h
    002     RLL     2011-03-12  changed from LCD to LED (7-seg)
                                for the display (4 digits xx.xx)

*/

// ---------------------------------------------------------

#ifndef _main_h_
#define _main_h_

#include <avr/io.h>
#include "mydefs.h"

#define	F_CPU           1e6             // 1 MHz
#include <util/delay.h>

// ---------------------------------------------------------

// define the LED connections:
// LED segments are active LOW

#define	LED_A		SBIT( PORTD, 0)
#define	LED_DDR_A	SBIT( DDRD, 0 )

#define	LED_B		SBIT( PORTD, 2 )
#define	LED_DDR_B	SBIT( DDRD, 2 )

#define	LED_C		SBIT( PORTD, 3 )
#define	LED_DDR_C	SBIT( DDRD, 3 )

#define	LED_D		SBIT( PORTD, 4 )
#define	LED_DDR_D	SBIT( DDRD, 4 )

#define	LED_E		SBIT( PORTD, 5 )
#define	LED_DDR_E	SBIT( DDRD, 5 )

#define	LED_F		SBIT( PORTD, 6 )
#define	LED_DDR_F	SBIT( DDRD, 6 )

#define	LED_G		SBIT( PORTD, 7 )
#define	LED_DDR_G	SBIT( DDRD, 7 )

#define LED_PORT    PORTD
#define LED_DDR     DDRD

// ---------------------------------------------------------

// digits are numbered xx.xx
//                     12.34
// definitions for xtors for the digits
// xtors are active LOW
#define LED_DIGIT_1         SBIT( PORTB, 7 )
#define	LED_DDR_DIGIT_1     SBIT( DDRB, 7 )

#define LED_DIGIT_2         SBIT( PORTB, 2 )
#define	LED_DDR_DIGIT_2     SBIT( DDRB, 2 )

#define LED_DIGIT_3         SBIT( PORTB, 1 )
#define	LED_DDR_DIGIT_3     SBIT( DDRB, 1 )

#define LED_DIGIT_4         SBIT( PORTB, 0 )
#define	LED_DDR_DIGIT_4     SBIT( DDRB, 0 )

// ---------------------------------------------------------

// other bit definitions
#define  ADC_AMP_PIN    PC0  // voltage from Vtest (voltage IN)

// port definitions
#define  ADC_PORT        PORTC
#define  ADC_DDR         DDRC

// define system flags
#define sys_flags               GPIOR0
#define sf_change_digit         0
#define start_adc_flag          1
#define adc_val_ready_flag      2
#define adc_avg_calc_flag       3
#define adc_new_pwm_flag        4



// ---------------------------------------------------------
// function prototypes

void io_init( void );
void ShowDigit( uint8_t );

// ---------------------------------------------------------

// constants

// definitions for the LED segments
#define  ZERO  0b11000000
#define  ONE   0b11111001
#define  TWO   0b10100100
#define  THREE 0b10110000
#define  FOUR  0b10011001
#define  FIVE  0b10010010
#define  SIX   0b10000010
#define  SEVEN 0b11111000
#define  EIGHT 0b10000000
#define  NINE  0b10010000

// ---------------------------------------------------------



// ---------------------------------------------------------

#endif  // for _main_h_
